package Eyjafjalla.relic;

import Eyjafjalla.effect.MarkFireBreathEffect;
import Eyjafjalla.helper.EyjafjallaHelper;
import Eyjafjalla.helper.StringHelper;
import Eyjafjalla.modcore.EyjafjallaTag;
import Eyjafjalla.modifier.FireMarkMod;
import Eyjafjalla.patch.CloudPatch;
import basemod.abstracts.CustomRelic;
import basemod.helpers.CardModifierManager;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.helpers.ImageMaster;
import com.megacrit.cardcrawl.relics.AbstractRelic;
import com.megacrit.cardcrawl.rooms.AbstractRoom;
import com.megacrit.cardcrawl.rooms.MonsterRoomBoss;
import com.megacrit.cardcrawl.rooms.MonsterRoomElite;
import com.megacrit.cardcrawl.vfx.cardManip.ShowCardBrieflyEffect;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Random;

public class DrawPen extends CustomRelic {

    public static final String ID = "eyjafjalla:DrawPen";

    public DrawPen(){
        super(ID, ImageMaster.loadImage(StringHelper.getRelicIMGPATH(ID,false)),ImageMaster.loadImage(StringHelper.getRelicIMGPATH(ID,true)),RelicTier.UNCOMMON,LandingSound.CLINK);
    }

    @Override
    public void onEnterRoom(AbstractRoom room) {
        if(!(room instanceof MonsterRoomElite)&&!(room instanceof MonsterRoomBoss))
            return;
        this.flash();
        ArrayList<AbstractCard> firableCards = new ArrayList<>();
        Iterator var2 = AbstractDungeon.player.masterDeck.group.iterator();
        while (var2.hasNext()) {
            AbstractCard c = (AbstractCard) var2.next();
            if ((c.type == AbstractCard.CardType.ATTACK || c.type == AbstractCard.CardType.SKILL || c.type == AbstractCard.CardType.POWER) && (!CloudPatch.CloudField.isFire.get(c)||c.hasTag(EyjafjallaTag.UNLIMITED_FIRE_EYJAFJALLA)) && CloudPatch.CloudField.showFire.get(c)) {
                firableCards.add(c);
            }
        }
        Collections.shuffle(firableCards, new Random(AbstractDungeon.miscRng.randomLong()));
        if (!firableCards.isEmpty()) {
            CardModifierManager.addModifier(firableCards.get(0), new FireMarkMod());
            AbstractCard c = firableCards.get(0).makeStatEquivalentCopy();
            AbstractDungeon.topLevelEffects.add(new ShowCardBrieflyEffect(c));
            AbstractDungeon.topLevelEffects.add(new MarkFireBreathEffect(c));
        }
        CardCrawlGame.sound.playA("ATTACK_FIRE", 0.3F);
    }

    @Override
    public String getUpdatedDescription() {
        return DESCRIPTIONS[0];
    }

    @Override
    public AbstractRelic makeCopy() {
        return new DrawPen();
    }
}



